home *** CD-ROM | disk | FTP | other *** search
Korn shell script | 1996-11-11 | 6.0 KB | 257 lines |
- #!/bin/ksh -p
- # setup correct directory from which to run Developer Toolbox
-
- export PATH="/usr/bsd:/bin:/usr/bin:/usr/sbin:/usr/bin/X11"
- fullprog=$0
- typeset -r prog=${0##*/}
- progdir=${0%/*}
- if [[ "$progdir" = \/* ]]; then
- typeset -r fullprogdir="$progdir"
- else
- [[ "$progdir" = "$fullprog" ]] && progdir="."
- cwd=$(pwd)
- cd $(pwd)/$progdir
- fullprogdir=$(pwd)
- cd $cwd
- typeset -r fullprogdir=$fullprogdir
- fi
- typeset -r fullprog="$fullprogdir/$prog"
- typeset -r progdir=$progdir
- typeset -r flags="hr"
- typeset -r getoptflags=":${flags}f:\?"
- typeset -r usage="Usage: $prog [-${flags}] [-f dir]"
- typeset -r numpositional=0
- if [[ "$TMPDIR" != "" ]]; then
- typeset -r tmpdir="$TMPDIR"
- elif [[ -d /usr/var/tmp ]]; then
- typeset -r tmpdir="/usr/var/tmp"
- else
- typeset -r tmpdir="/tmp"
- fi
- typeset -r tmp=$tmpdir/$prog.$$
- cleanuplist="$tmp"
- typeset -r SigList="INT QUIT TERM HUP"
- typeset errexit=0
- trap "trap - EXIT $SigList; CleanUp" EXIT
- trap exit $SigList
-
- # include this at beginning of each function as well
- if [ "$DEBUG" ] ; then set -$DEBUG ; : Debug enabled by envariable ; fi
-
- Usage () {
- echo "$usage"
- echo " -h Help text (this stuff)."
- echo " -r Remove local viewDT directory."
- echo " -f dir Run from directory dir."
- }
-
- Exit() {
- [ "$1" ] && echo "$*" >&2
- errexit=1
- exit
- }
-
- UsageExit() {
- [ "$1" ] && echo "$*" >&2
- Usage >&2
- Exit
- }
-
- Log () {
- [[ "$verbose" = yes ]] && echo >&2 "$@"
- }
-
- Do () {
- [[ ! -z "$verbose" || ! -z "$noexecute" ]] && echo >&2 "$@"
- [[ -z "$noexecute" ]] && "$@"
- typeset evalstatus=$?
- [[ ! -z "$noexecute" || $evalstatus = 0 ]]
- }
-
- DoExit () {
- Do $1 || Exit "$2"
- }
-
- DoUsageExit () {
- Do $1 || UsageExit "$2"
- }
-
- CleanUp () {
- : Add your own clean-up actions here
-
- eval /bin/rm -fr $cleanuplist
- exit $errexit
- }
-
- # Setexecutable variable_to_set executable absolute_path
- # also looks in same place this code came from
- SetExecutable () {
- set -$DEBUG
- typeset executable
- executable=$(whence $2)
- if [ "$executable" = "''" ] ; then
- executable=$(whence $progdir/$2)
- if [ "$executable" = "''" ] ; then
- executable=$3
- fi
- fi
- [ -x $executable ] || return 1
- # this strips leading ././* to single ./
- # [ "$( echo $executable | sed -e 's%^\./.*%%')" = "" ] &&
- # executable="./${executable##*(./)}"
- eval $1=\""$executable"\"
- return 0
- }
-
- SetExecExit () {
- set -$DEBUG
- SetExecutable $1 $2 $3 ||
- Exit "Unable to locate $2 for execution"
- }
-
- unset verbose noexecute removeDT viewDT_file
- while getopts ${getoptflags} flag; do
- case $flag in
- f)
- viewDT_file="$viewDT_file $OPTARG"
- ;;
- h | \?)
- Usage >&2
- exit
- ;;
- r)
- removeDT=-r
- ;;
- esac
- done
- shift OPTIND-1
-
- if (( $# != $numpositional )) ; then
- Usage >&2
- Exit
- fi
-
- #functions
- ###############################################################################
-
- bad_cd_msg() {
- $DT_xconfirm error "\
- The janitor needs to install perl from the\
- \"Developer Toolbox 6.0\" CD\n\
- which has a \"2\" printed by the rat's tail\n\
- Please place it in the CDROM drive and re-run viewDT."
- }
-
- root_test() {
- ((root_checked=1))
- /bin/id | read r _
- if [[ "$r" != "uid=0(root)" ]]; then
- $DT_xconfirm error \
- "The janitor needs to temporarily be superuser\
- to enable you to view the data of the toolbox.\n\n\
- Please become superuser and then re-run viewDT."
- Exit
- fi
- }
- perl_load() {
- root_test
- if [[ ! -f $CDROM_ROOT/.IM ]]; then
- bad_cd_msg
- Exit
- fi
- grep "id" $CDROM_ROOT/.IM | head -1 | read _ _ id
- if [[ "$id" != "\"58\"" ]]; then
- bad_cd_msg
- Exit
- fi
- cd $fullprogdir
- rm -rf tmp_perl > /dev/null 2>&1
- mkdir tmp_perl
- cd tmp_perl
- echo " ... extracting freeware perl inst images"
- tar xBf $CDROM_ROOT/toolbox/public/freeware1.0/fw_LWperl5/fw_LWperl5.tardist || Exit
- echo " ... installing freeware perl inst images"
- inst -a -f . -I fw_LWperl5 -I fw_common -K fw_LWperl5.src.perl || Exit
- echo " ... symbolic linking freeware perl to /bin/perl"
- rm -rf /bin/perl > /dev/null 2>&1
- ln -s /usr/freeware/bin/perl /bin/perl || Exit
- cd $fullprogdir
- rm -rf tmp_perl > /dev/null 2>&1
- }
- symlink_chk() {
- typeset need=$1 got r
- [[ -f $need ]] && return
- if [[ -f /usr/freeware/bin/perl ]]; then
- got=/usr/freeware/bin/perl
- elif [[ -f /usr/sbin/perl ]]; then
- got=/usr/sbin/perl
- else
- $DT_xconfirm error "Unable to find perl on your system."
- Exit
- fi
- if ((root_checked)); then
- r=$($DT_xconfirm yesno \
- "The janitor needs to create a symlink \
- from $got to $need\n\n\
- Should I make the symlink?\n\n\
- Note: Without this symlink, you will not be able to\
- view the toolbox.")
- [[ "$r" = "No" ]] && Exit
- else
- r=$($DT_xconfirm yesno \
- "The janitor needs to create a symlink \
- from $got to $need\n\n\
- IF you did not invoke viewDT as superuser,\n\
- You will need to press No,\
- become superuser and re-run viewDT\n\
- Should I make the symlink?\n\n\
- Note: Without this symlink, you will not be able to\
- view the toolbox.")
- [[ "$r" = "No" ]] && Exit
- root_test
- fi
- echo " ... symbolic linking freeware perl to $need"
- rm -rf $need > /dev/null 2>&1
- ln -s $got $need
- }
-
- #start
- ###############################################################################
- typeset -i root_checked=0
- DT_xconfirm="$fullprogdir/DT_xconfirm"
- if [[ "$CDROM_ROOT" = "" ]]; then
- $DT_xconfirm notviewDT
- Exit
- fi
- if [[ ! -d $CDROM_ROOT/toolbox ]]; then
- $DT_xconfirm error "\
- You must run this as viewDT from\n\
- a Developer Toolbox CD directory"
- Exit
- fi
-
- if [[ -f /usr/sbin/perl ]]; then
- continue
- elif [[ -f /usr/freeware/bin/perl ]]; then
- continue
- else
- r=$($DT_xconfirm yesno \
- "The janitor needs to install perl on your system.\n\
- IF you did not invoke viewDT as superuser\n\
- OR if the \"Developer Toolbox 6.0\" CD\n\
- labeled with a \"2\" by the rat's tail\n\
- is not in the CDROM drive,\n\
- THEN you will need to press No and do these things.\n\n\
- Should I install perl on your system?\n\
- Note: Without perl, you will not be able to\
- view the toolbox.")
- [[ "$r" = "No" ]] && Exit
- perl_load
- fi
- symlink_chk /bin/perl
- symlink_chk /usr/sbin/perl
- if ((root_checked)); then
- echo "perl will now work correctly when you next run viewDT"
- Exit
- fi
-